package br.fmapn.web.util;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import br.fmapn.register.BusinessProcessServicesRemote;
import br.fmapn.reporter.BusinessProcessReporterRemote;


/**
 * 
 * @author heitor
 *
 */
public class GerenciadorLookup {
	

	private static BusinessProcessServicesRemote businessProcessServices;
	
	private static BusinessProcessReporterRemote businessProcessReporter;
	
	private static InitialContext initialContext;
	 
	public GerenciadorLookup() {
		try {
			initialContext = new InitialContext();
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}

	private static Object getContextLookup(String lookup) {
		Object bean = null;
		if (initialContext == null) {
			try {
				initialContext = new InitialContext();
			} catch (NamingException e) {
				e.printStackTrace();
			}
		}
		try {
			bean = initialContext.lookup(lookup);
		} catch (NamingException e) {
			e.printStackTrace();
		}

		return bean;
	}

	public static BusinessProcessServicesRemote obterBusinessProcessServices() {
		if (businessProcessServices == null) {
			businessProcessServices = (BusinessProcessServicesRemote) getContextLookup("FMAPN-ear/BusinessProcessServices/remote");
		}
		return businessProcessServices;
	}
	
	public static BusinessProcessReporterRemote obterBusinessProcessReporter() {
		if (businessProcessReporter == null) {
			businessProcessReporter = (BusinessProcessReporterRemote) getContextLookup("FMAPN-ear/BusinessProcessReporter/remote");
		}
		return businessProcessReporter;
	}
	

}
